﻿// SyntheticDataGenerator.Generators.SeedGenerator
//
// (c) 2011 Arthur Pitman
//
// Part of Market-Basket Synthetic Data Generator
// A C# adaptation of the IBM Quest Market-Basket Synthetic Data Generator
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// (Version 2) as published by the Free Software Foundation.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License (Version 2) along with this program; if not, write to 
// the Free Software Foundation, Inc., 
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// or see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SyntheticDataGenerator.Generators
{
    /// <summary>
    /// Generates seeds for other random generators
    /// </summary>
    public class SeedGenerator
    {
        /// <summary>
        /// The uniform generator used to generate seeds
        /// </summary>        
        protected static UniformGenerator seedDistribution;

        /// <summary>
        /// Static constructor for <see cref="SeedGenerator"/>
        /// </summary>
        static SeedGenerator()
        {
            Random random = new Random();            
            seedDistribution = new UniformGenerator(-random.Next());
        }

        /// <summary>
        /// Sets the master seed used by the <see cref="SeedGenerator"/>
        /// </summary>
        /// <param name="masterSeed"></param>
        public static void SetMasterSeed(int masterSeed)
        {
            seedDistribution = new UniformGenerator(masterSeed);
        }

        /// <summary>
        /// Returns a seed
        /// </summary>
        /// <returns>A seed</returns>
        public static int Next()
        {
            double x = seedDistribution.Next() * seedDistribution.Next();
            return (int)(-int.MaxValue * x);            
        }
    }
}
